import image_bar from '@/assets/exploitation/barbright.png'
import image_pie from '@/assets/exploitation/piebright.png'
import image_line from '@/assets/exploitation/linebright.png'
import image_scatter from '@/assets/exploitation/scatterbright.png'

export const queryFormItem = (handleDeptOnchange) => {
  return [
    {
      type: 'select',
      key: 'deptId',
      otherAttrs: {
        placeholder: '考核部门',
        filterable: true
      },
      options: [],
      slotListeners: {
        change: handleDeptOnchange
      }
    },
    {
      type: 'select',
      key: 'checkTopic',
      otherAttrs: {
        style: {
          width: '140px'
        },
        placeholder: '考核主题'
      },
      options: []
    },
    {
      type: 'select',
      key: 'kpiServerId',
      otherAttrs: {
        style: {
          width: '140px'
        },
        placeholder: '指标服务器'
      },
      options: []
      // options: exploitSystemMap
    },
    {
      type: 'select',
      key: 'dateSystemId',
      otherAttrs: {
        style: {
          width: '140px'
        },
        placeholder: '数据系统'
      },
      options: []
      // options: exploitSystemMap
    },
    {
      type: 'date',
      key: 'beginDate',
      otherAttrs: {
        placeholder: '开始日期'
      }
    },
    {
      type: 'date',
      key: 'endDate',
      otherAttrs: {
        placeholder: '结束日期'
      }
    },
    {
      type: 'input',
      key: 'keyword',
      otherAttrs: {
        placeholder: '指标名称'
      }
    }
  ]
}
// 状态: 1=启用 2=停用
const formatStatus = scope => {
  const result = {
    value: '',
    color: ''
  }
  switch (scope.row.status) {
    case 1:
      result.value = '启用'
      break
    case 2:
      result.value = '停用'
      result.color = '#a8a8a8'
      break
    default:
      break
  }
  return result
}
export const tableColumn = (page, size) => {
  return [
    {
      key: 'checkDeptName',
      label: '考核部门',
      minWidth: 120
    },
    {
      key: 'checkTopic',
      label: '考核主题',
      minWidth: 120
    },
    {
      key: 'kpiServerName',
      label: '指标服务器',
      minWidth: 120
    },
    {
      key: 'name',
      label: '指标名称',
      minWidth: 120
    },
    {
      key: 'status',
      label: '状态',
      minWidth: 80,
      render: (h, scope) => (
        <span style={'color:' + formatStatus(scope).color}>
          {formatStatus(scope).value}
        </span>
      )
    },
    {
      key: 'checkCount',
      label: '考核次数',
      minWidth: 80
    },
    {
      key: 'relationCount',
      label: '关联次数',
      minWidth: 80
    }
    // {
    //   key: 'createName',
    //   label: '创建人',
    //   minWidth: 120
    // },
    // {
    //   key: 'createTime',
    //   label: '创建时间',
    //   minWidth: 200,
    //   render: (_, rocord) => parseTime(rocord.row.createTime)
    // }
  ]
}

export const updateFormItem = (
  handleDeptOnchange,
  handleUserTree,
  handleDefaultSelect,
  handlekpinNameOnchange
) => {
  return [
    {
      type: 'input',
      key: 'name',
      label: '指标名称',
      col: 12,
      required: true,
      slotAttrs: {
        style: {
          width: '248px'
        }
      },
      slotListeners: {
        change: handlekpinNameOnchange
      }
    },
    {
      type: 'select',
      key: 'checkDeptId',
      label: '考核部门',
      col: 12,
      required: true,
      slotListeners: {
        change: handleDeptOnchange
      },
      slotAttrs: {
        filterable: true,
        style: {
          width: '248px'
        },
        options: []
      }
    },
    {
      type: 'select',
      key: 'checkTopic',
      label: '考核主题',
      col: 12,
      required: true,
      slotAttrs: {
        style: {
          width: '248px'
        },
        options: []
      }
    },
    {
      type: 'select',
      key: 'kpiServerId',
      label: '指标服务器',
      col: 12,
      required: true,
      slotAttrs: {
        style: {
          width: '248px'
        },
        options: []
      }
    },
    {
      type: 'select',
      key: 'dateSystemId',
      label: '数据系统',
      col: 12,
      required: true,
      slotAttrs: {
        style: {
          width: '248px'
        },
        options: []
      }
    },
    {
      type: 'select',
      key: 'apiType',
      label: '接口类型',
      col: 12,
      required: true,
      slotAttrs: {
        style: {
          width: '248px'
        },
        options: [
          {
            key: 1,
            value: '接口类型1'
          }
        ]
      }
    },
    {
      type: 'input',
      key: 'responsibleAccountNames',
      label: '责任人',
      col: 24,
      required: true,
      slotAttrs: {
        disabled: true,
        style: {
          width: '97.5%'
        },
        slots: [
          {
            labelName: 'button',
            icon: 'el-icon-s-tools',
            name: 'append',
            listen: {
              click: handleUserTree
            }
          }
        ]
      }
      // slotListeners: {
      //   blur: handleUserTree
      // }
    },
    {
      type: 'input',
      key: 'apiUrl',
      label: '接口地址',
      col: 12,
      required: true,
      slotAttrs: {
        style: {
          width: '248px'
        }
      }
    },
    {
      type: 'select',
      key: 'kpiType',
      label: '指标类型',
      col: 12,
      // required: true,
      slotAttrs: {
        options: [{ key: 1, value: '每日核算' }, { key: 2, value: '累计核算' }],
        style: {
          width: '248px'
        }
      }
    },
    {
      type: 'textarea',
      key: 'apiDesc',
      label: '指标描述',
      col: 24,
      slotAttrs: {
        style: {
          width: '97.5%',
          height: '300%'
        }
      }
    },
    {
      type: 'radio',
      key: 'defaultChart',
      label: '默认图表', // 引用的地方在哪
      slotListeners: {
        change: handleDefaultSelect
        // blur: () => {
        //   console.log(7777777)
        // }
      },
      slotAttrs: {
        options: [
          { key: 1, value: image_bar },
          { key: 2, value: image_pie },
          { key: 3, value: image_line },
          { key: 4, value: image_scatter }
        ],
        valType: 'img'
      },
      val: 0,
      col: 24
    }
  ]
}
